package com.java2_7;

import javax.xml.parsers.SAXParser;
import java.util.ArrayList;
import java.util.Scanner;

public class java2_7 {
    //    //    public static void main(String[] args) {
////
////        ArrayList<String> list = new ArrayList<>();  //创建一个集合名为list
////        //想集合中一添加元素
////        list.add("这是一个小插曲！");
////        list.add("我是练习时长");
////        list.add("两年半的");
////        list.add("偶像练习生");
////
////        //遍历集合
////        for (int i = 0; i < list.size(); i++) {
////            System.out.print(list.get(i) + " ");
////        }
////
////    }
////public static void main(String[] args) {
////
//////    Student.luckNumber += 1;
//////    System.out.println(Student.luckNumber);
//////    Student s = new Student();
//////    System.out.println(s.luckNumber);
////    Student s = new Student();
////    s.setName("coco");
////    System.out.println(s.getName());
////    //实例成员变量要创造对象在使用，而静态成员变量可以直接类.使用
////    Student s2 = new Student();
////    System.out.println(s2.luckNumber++);
////    Student s1 = new Student();
////    System.out.println(s2.luckNumber);
////    Student.luckNumber+=100;
////    System.out.println(Student.luckNumber);
////}
////public static void main(String[] args) {
////
////    int ret = carInformation.add(12, 23);
////    System.out.println(ret);
////    carInformation c = new carInformation();
////    System.out.println(c.add(123, 234));
////    //静态方法变量可以直接调用，而实例方法变量则不可以
////}
////
////public static void main(String[] args) {
////    //方法类
////    System.out.println(util.verifyNumber());
////
////}
////    public static void main(String[] args) {
////        card c = new card();
////        System.out.println(c.getName());
////
////    }
////    public static void main(String[] args) {
////
////        //静态代码块的初始化
////        System.out.println(card.cards);
////    }
//    public static void main(String[] args) {
//        danli s1 = danli.instance;
//        danli s2 = danli.instance;
//        System.out.println(s1 == s2);
//
//    }
//public static void main(String[] args) {
//    //danli s1 = new danli();
//    danli s1 = danli.instance;
//    danli s2 = danli.instance;
//}
//public static void main(String[] args) {
//
//    //danli d = new danli();
//    danli d = danli.getInstance();
//    System.out.println(d);
//    danli d2 = danli.getInstance();
//    System.out.println(d2);
//}
//
//
//    public static void main(String[] args) {
//        ArrayList<Integer> list = new ArrayList<>();
//        for (int i = 1; i <= 10; i++) {
//            list.add(i);
//        }
//        //遍历
//        System.out.println(list);
//
//        //删除
////        for (int j = 0; j < list.size(); j++) {
////            list.remove(j);
////        }
////        System.out.println(list);
//        for (int i = list.size() - 1; i >= 0; i--) {
//            list.remove(i);
//        }
//        System.out.println(list);
//    }
    //集合删除元素要从后往前删除
    public static void main(String[] args) {
        ArrayList<classStudents> member = new ArrayList<>();
        member.add(new classStudents("zhangsan", 20, 1));
        member.add(new classStudents("lisi", 21, 2));
        member.add(new classStudents("wangwu", 22, 3));
        member.add(new classStudents("zhaoliu", 20, 4));

//        for (int i = 0; i < member.size(); i++) {
//            classStudents s = member.get(i);
//            System.out.println(s.getName() + "\t\t\t\t" + s.getAge() + "\t\t\t\t" + s.getIndex());
//        }

        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.print("请输入学生的学号：");
            int studentid = sc.nextInt();
            if (studentid>0 && studentid<= member.size()) {
                classStudents ret = mem(member, studentid);
                System.out.println(ret.getName() + "\t\t\t\t" + ret.getAge() + "\t\t\t\t" + ret.getIndex());
            } else {
                System.out.println("对不起，您输入的数据有误");
            }
        }

    }

    //存储的是类即相应的地址；
    public static classStudents mem(ArrayList<classStudents> member,int index) {
        for (int i = 0; i < member.size(); i++) {
            classStudents s = member.get(i);
            if(s.getIndex() == index){
                return s;
            }
        }
        return null;
    }

}
